/*
 * get the xml from webpage
 */
package com.sysu.minsysu.zxcx;


import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HtmlServices {

	/**
	* @param args
	* @throws Throwable 
	*/
	public InputStream readHtml( String string ) throws Throwable{
	   String path = string;
	   URL url = new URL(path);
	   HttpURLConnection conn = ( HttpURLConnection )url.openConnection();
	   conn.setConnectTimeout( 5*1000 );
	   conn.setRequestMethod( "GET" );
	   if( conn.getResponseCode() == 200 ){
		   InputStream inputStream = ( InputStream )conn.getInputStream();
//		   return readStream(inputStream);	
		   return inputStream;
	   }else{
		   throw new Exception( "网络异常，读取失败！");
	   }

	}
//
//	private static byte[] readStream( InputStream inputStream ) throws Throwable {
//	   ByteArrayOutputStream outStream = new ByteArrayOutputStream();
//	   byte []buffer = new byte[1024];
//	   int len = 0;
//	   while((len=inputStream.read(buffer)) != -1){
//		   outStream.write(buffer, 0, len);
//	   
//	   }
//	   inputStream.close();
//	   outStream.close();
//	   return outStream.toByteArray();
//	}
}
